

#ifndef STK8321_H__
#define STK8321_H__

#include <stdint.h>


const uint8_t normal_mode_reg_config[][2] = 
{
//    {0x21, 0x8F},// INTCFG2, reset latched interrupt pin 
//    {0x14, 0xB6},// SWRST, reset all register to default value 

    {0x11, 0x74},// PWRMODE, low power mode, ESD, 25Hz
    {0x0F, 0x03},// RANGESEL, 2G
    {0x10, 0x0D},// BWSEL, BW=31.25Hz, ODR=2*BW(actual data rate = 36Hz)

    {0x13, 0x00},// DATASETUP,  
    {0x16, 0x00},// INTEN1, disable All any motion interrupt
    {0x17, 0x40},// INTEN2, FIFO watermark/Full interrupt 
    {0x19, 0x00},// INTMAP1, disable any motion/signification motion on INT1/INT2
    {0x1A, 0x02},// INTMAP2, enable FIFO watermark/full interrupt to INT1
    {0x20, 0x00},// INTCFG1, Active LOW, output push-pull 
    {0x21, 0x8F},// INTCFG2, reset latch-pin, set interrupt LATCH

    {0x3D, 0x0A},// FIFOCFG1, set watermark level = 0x0C,(1frame = X/Y/Z) 
    {0x3E, 0xC4},// FIFOCFG2, stream mode, subsample interval = 1, datasource XYZ
    
    {0x5E, 0xC0},
    {0x34, 0x04}, 
};

const uint8_t sleep_mode_reg_config[][2] = 
{
    {0x3E, 0x00},// FIFOCFG2, bypass FIFO mode
    {0x11, 0x5A},// PWEMODE, enable low power mode, event-diven

    {0x0F, 0x03},// RANGESEL, 2G(set suspend mode before changing )
    {0x10, 0x09},// BWSEL, 15.63Hz(set suspend mode before changing )

    {0x13, 0x40},// DATASETUP, data protected, filtered
    {0x16, 0x07},// INTEN1, enable axis anymotion interrupt
    {0x17, 0x00},// INTEN2, disable FWM,FFULL,DATA interrupt
    {0x19, 0x04},// INTMAP1, significant/any motion interrupt to INT1
    {0x1A, 0x00},// INTMAP2, disable NEWDATA/FIFO FULL/FIFOWM 
    {0x20, 0x00},// INTCFG1, active LOW, 
    {0x21, 0x0F},// INTCFG2, INT latch
    {0x27, 0x02},// SLOPEDLY, 1
    {0x28, 0x07},// SLOPETHD, 2.91mg*10 
    {0x29, 0x0A},// SIGMOT1, 1LSB=20ms
    {0x2A, 0x04},// SIGMOT2, any motion enable 
    {0x2B, 0x0A},// SIGMOT3, 1LSB=20ms,    
};

const uint8_t reset_mode_reg_config[][2] = 
{
    {0x21, 0xBF},// INTCFG2, reset latched interrupt pin 
    {0x14, 0xB6},// SWRST, reset all register to default value 
};

const uint8_t fifo_mode_reg_config[][2] = 
{
//    {0x21, 0x8F},// INTCFG2, reset latched interrupt pin 
//    {0x14, 0xB6},// SWRST, reset all register to default value 

    {0x11, 0x74},// PWRMODE, low power mode, ESD, 25Hz
    {0x0F, 0x03},// RANGESEL, 2G
    {0x10, 0x0D},// BWSEL, BW=31.25Hz, ODR=2*BW(actual data rate = 36Hz)

    {0x13, 0x00},// DATASETUP,  
    {0x16, 0x00},// INTEN1, disable All any motion interrupt
    {0x17, 0x40},// INTEN2, FIFO watermark/Full interrupt 
    {0x19, 0x00},// INTMAP1, disable any motion/signification motion on INT1/INT2
    {0x1A, 0x02},// INTMAP2, enable FIFO watermark/full interrupt to INT1
    {0x20, 0x00},// INTCFG1, Active LOW, output push-pull 
    {0x21, 0x8F},// INTCFG2, reset latch-pin, set interrupt LATCH

    {0x3D, 0x0A},// FIFOCFG1, set watermark level = 0x0C,(1frame = X/Y/Z) 
    {0x3E, 0xC4},// FIFOCFG2, stream mode, subsample interval = 1, datasource XYZ
    
    {0x5E, 0xC0},
    {0x34, 0x04},
};

const uint8_t stop_reg_config[][2] = 
{
    {0x16, 0x00},
    {0x17, 0x00},
    {0x19, 0x00}, // disable All interrupt
    {0x1A, 0x00}, // 
    {0x11, 0x80},// PWRMODE power-off
};

#endif 

